;; The first four lines of this file were added by Dracula.
;; They tell DrScheme that this is a Dracula Modular ACL2 program.
;; Leave these lines unchanged so that DrScheme can properly load this file.
#reader(planet "reader.rkt" ("cce" "dracula.plt") "modular" "lang")
(require "mbmptree.lisp")
(require "mavltree.lisp")
(require "iborder.lisp")

(module Mborder
  (import Ibmptree)
  
  (defun copy-row (src-tr src-x src-y dest-tr dest-x dest-y width)
    (if (zp width)
        dest-tr
        (copy-row src-tr (1+ src-x) src-y
                  (insert-pixel dest-tr (list dest-y dest-x (get-pixel-color src-tr src-y src-x)))
                  (1+ dest-x) dest-y (1- width))))
  
  (defun copy-rows (src-tr src-x src-y dest-tr dest-x dest-y height width)
    (if (zp height)
        dest-tr
        (copy-rows src-tr src-x (1+ src-y)
                   (copy-row src-tr src-x src-y
                             dest-tr dest-x dest-y width)
                   dest-x (1+ dest-y)
                   (1- height) width)))
  
  
  (defun border (tr thickness r g b)
    (if (and (bmp-tree? tr)
             (natp thickness)
             (rgb? (list r g b)))
        (copy-rows tr 0 0 
                   (make-solid-color-image (+ (* 2 thickness)
                                              (car (get-dimensions tr)))
                                           (+ (* 2 thickness)
                                              (cdr (get-dimensions tr)))
                                           r g b)
                   thickness
                   thickness
                   (car (get-dimensions tr))
                   (cdr (get-dimensions tr)))
        nil))
  
  (export Iborder))